﻿using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Ndex.Core.Service
{
    [DataContract]
    public class GenericResponse<T> : ServiceResponse
    {
        [DataMember]
        public T Data { get; set; }

        public GenericResponse() { }

        public GenericResponse(ServiceRequest request)
            : base(request) { }

        public GenericResponse<T> SetData(T data)
        {
            Data = HasError ? default(T) : data;
            return this;
        }

        public GenericResponse<T> SetData(T successData, T failData)
        {
            Data = HasError ? failData : successData;
            return this;
        }

        public GenericResponse<T> SetData(List<ValidationModel> errors, T data)
        {
            Errors.AddRange(errors);
            SetData(data);
            return this;
        }
    }
}